﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="group_personal_tree.aspx.cs" Inherits="Ccit.OA.Group.group_personal_tree" %>
<%@ Register assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="Microsoft.Web.UI.WebControls" tagprefix="iewc" %>
<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
     <style>
		.skin { BORDER-RIGHT: buttonhighlight 2px outset; BORDER-TOP: buttonhighlight 2px outset; FONT-SIZE: 9pt; VISIBILITY: hidden; BORDER-LEFT: buttonhighlight 2px outset; WIDTH: 100px; CURSOR: default; BORDER-BOTTOM: buttonhighlight 2px outset; FONT-FAMILY: Arial, Helvetica, sans-serif; POSITION: absolute; BACKGROUND-COLOR: menu; TEXT-ALIGN: left }
		.menuitems { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-TOP: 5px; PADDING-BOTTOM: 5px;}
	</style>    
    <script language="javascript" src="../script/jquery.js" type="text/javascript"></script>
    <script language="javascript" src="../script/StringClass_Ext.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jsonlib.js" type="text/javascript"></script>
    <script language="javascript" src="../script/jbase64.js" type="text/javascript"></script>
</head>
<body onclick="hideMenu()">
    <ccit:ActionForm id="form1" runat="server"> 
   <input type="hidden" id="_hidType" runat="server" />
    <input type="hidden" id="_hidUpAddrId" runat="server" />  
    <input type="hidden" id="_hidAddNewSign" runat="server" /> <!-- 新增记录标志 --> 
        <!--保存后传来的主键id-->
    <input type="hidden" id="_hidNewColumnId" runat="server" /> 
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server"></asp:ScriptManager>  
     <iewc:TreeView ID="trvDepAddress" runat="server">
    </iewc:TreeView>  
    <div id="root" class="skin" style="LEFT:0px; VISIBILITY:hidden; WIDTH:80px; TOP:0px; HEIGHT:35px">    
        <div onclick="clickItem()" onMouseover="highlighItem()" onMouseout="lowlightItem()" style="BORDER-BOTTOM: window 2px inset;" class="menuitems" func="EditSubAddress">            
                <img src="../images/toolbar/addnew_bq.gif" border="0" />&nbsp; 编辑        
        </div>
        
        <div onclick="clickItem()" onMouseover="highlighItem()" onMouseout="lowlightItem()" class="menuitems" func="DeleteAddress">
            <img src="../images/toolbar/del_bq.gif" border="0" />&nbsp; 删除
        </div>
    </div> 
    
    <br />
    <!--编辑页面保存成功的时候  调用的事件-->
    <input type="button" id="btnTrigger" onclick="doTrigger()" style="display:none" value="触发事件" />
    <!--编辑页面删除成功的时候  调用的事件-->
    <input type="button" id="btnDelTrigger" onclick="doDelTrigger()" style="display:none" value="删除触发事件" />
    <script type="text/javascript">
    <!--
        var menuskin = "skin";
		var node = null;
		var menuname = "root";	 
		 
		function hideMenu() 
		{		    
			var obj = document.getElementById(menuname);
			if (null != obj && typeof(obj) != "undefined")
				document.getElementById(menuname).style.visibility = "hidden";
		}
		
		function highlighItem() 
		{
			if (event.srcElement.className == "menuitems") 
			{
				event.srcElement.style.backgroundColor = "highlight";
				event.srcElement.style.color = "white";
			}
		}
		function lowlightItem() 
		{
			if (event.srcElement.className == "menuitems") 
			{
				event.srcElement.style.backgroundColor = "";
				event.srcElement.style.color = "black";
				window.status = "";
			}
		}
		///右键菜单判断是否是子节点信息
		function clickItem() 
		{								
			if(node != null)
			{
				var vNodeId = node.getAttribute("ID");
//				alert(vNodeId);				
				var nodeType = node.getAttribute("type").toUpperCase();		 
				var vNodeIdArray = vNodeId.split("_");
				var vAddressId = vNodeIdArray[0]; 
			    clickItemInfo(vAddressId); 
			}
		}
		///右键菜单 新增和删除的链接url
		function clickItemInfo(vAddressId)
		{		    
		    if (event.srcElement.className == "menuitems" && event.srcElement.disabled != true) 
	        {
		        var sFuncName = event.srcElement.getAttribute("func");	
		        document.getElementById("_hidUpAddrId").value = vAddressId;				
		        var vtype = document.getElementById("_hidType").value;
		        switch (sFuncName)
		        {
			        case "EditSubAddress":	//addnew sub dep address  
			            var sParam = "Id=" +vAddressId+"&type="+vtype;
			            var encodeParam = base64encode(sParam);
				        parent.frames[1].location.href = "group_personal_edit.aspx?"+encodeParam; 				
				        break;
			        case "DeleteAddress": //delete address						    
			            if(!confirm("删除当前节点同时会删除该节点下的所有成员信息,是否继续?"))
                            return; 
                        var nodeIndex = node.getNodeIndex();                            
                        PageMethods.DeleteGroup(vAddressId,nodeIndex,ClientCallBack);						    
				        break;
			        default: 
				        break;
		        }	
	         }
		}
		///节点展开
		function trvDepAddress.onexpand()
		{	
		    /* Step 1：find current click TreeNode */	    
		    var nodeIndex = event.treeNodeIndex;	
		    //alert(nodeIndex);		
			if (typeof(nodeIndex) == "undefined"){			
				node = null;
				return false;
			} 
			trvDepAddress.selectedNodeIndex = nodeIndex;
			node = trvDepAddress.getTreeNode(nodeIndex);
						
			/* Step 2: get asset type id，and get all child types */			
			var vNodeId = node.getAttribute("ID");
			var vNodeIdArray = vNodeId.split("_")
			var vAddressId = vNodeIdArray[0]; 
			
			if(vAddressId != "0") {
			    var oSubNodes = node.getChildren();
			    var oSubNode;
			    for(var i = oSubNodes.length - 1; i >= 0; i --) {
			        oSubNode = oSubNodes[i];
			        oSubNode.remove();
			    } 
			}
			hideMenu();
		}
		 
		///节点收缩
		function trvDepAddress.oncollapse()
		{
			hideMenu();
		}
		///更改节点属性值的时候
		function trvDepAddress.oncontextmenu()
		{				
			hideMenu();
			var nodeIndex = event.treeNodeIndex;							
			if (typeof(nodeIndex) == "undefined")
			{
				node = null;
				return false;
			}
			trvDepAddress.selectedNodeIndex = nodeIndex;
			node = trvDepAddress.getTreeNode(nodeIndex);			
			var vNodeId = node.getAttribute("ID");			
			var vNodeIdArray = vNodeId.split("_");
			var vAddressId = vNodeIdArray[0];
			　
			
			if(vAddressId == "0") return;  //根节点不显示右键菜单
			　
			var obj = document.getElementById("root");				
			if (null == obj || typeof(obj) == "undefined")
			{
				node = null;
				return false;
			}
			
			var rightedge = document.body.clientWidth - event.clientX;		//右边距
			var bottomedge = document.body.clientHeight - event.clientY;	//底边距
			
			if (rightedge < obj.offsetWidth)
				obj.style.left = document.body.scrollLeft + 5 + event.clientX - obj.offsetWidth;
			else
				obj.style.left = document.body.scrollLeft + 5 + event.clientX ;
			
			if (bottomedge < obj.offsetHeight)
				obj.style.top = document.body.scrollTop + 5 + event.clientY - obj.offsetHeight ;
			else
				obj.style.top = document.body.scrollTop + 5 + event.clientY ;
											
			obj.style.visibility = "visible";
			return false;
		}	
		 
		function ClientCallBack(vResult) {
		    //alert(vResult);	    
		    var oXMLDoc = new ActiveXObject("Microsoft.XMLDOM");  
            oXMLDoc.loadXML(vResult);
            
            var vOperType = $(oXMLDoc).find("OPERTYPE").text();     //operation type
            var vExeResult = $(oXMLDoc).find("EXERESULT").text();   //execute result    
               
            var expandSign = $(oXMLDoc).find("ExpandSign").text();  //operation expandSign
            var levelStruct =$(oXMLDoc).find("LevelStruct").text(); //execute levelStruct   
            var parentNodeId=$(oXMLDoc).find("NodeId").text();      //execute NodeId   
            var nodeIndex;
            switch(vOperType) { 
                case "ADDRDELETE":  //delete address
                    nodeIndex = $(oXMLDoc).find("NODEINDEX").text();    
                    eval("var resultObj=" + vExeResult);
                    alert(resultObj.message);
                    if(parseInt(resultObj.resultSign) > 0) { 
                        var node = $get("trvDepAddress").getTreeNode(nodeIndex); 
                        node.remove();  
                        nodeIndex = trvDepAddress.selectedNodeIndex;
                        node = trvDepAddress.getTreeNode(nodeIndex); 
		                /* Step 2: get asset type id，and get all child types */			
		                var vNodeId = node.getAttribute("ID");
		                var vNodeIdArray = vNodeId.split("_")
		                var vAddressId = vNodeIdArray[0]; 
		                document.getElementById("_hidUpAddrId").value = vAddressId;
                        var organPageParam="GroupId="+vAddressId;     
                        var organEncodeParam=base64encode(organPageParam);
                        var URL = "group_personal_list.aspx?"+organEncodeParam;
                        parent.frames[1].document.location.href= URL;  
                    }             
                    break;                 
            }
            
            oXMLDoc = null; 
        } 
        //追加子节点
         
        ///查找节点
        function findTreeNode(findAstTypeId) {
            var ctrlTree = document.getElementById("trvDepAddress");		    
		    
		    var ctrlRoot = ctrlTree.getTreeNode("0"); 
		    var ctrlChildNodes = ctrlRoot.getChildren();
	    
		    var ctrlFindNode = recursionFind(ctrlChildNodes,findAstTypeId);
            return ctrlFindNode;

        }
        
        function recursionFind(ctrlChildNodes,findAddrId) {
            var iLen = ctrlChildNodes.length;
            var ctrlTreeNode;
		    var vNodeId;
		    var vNodeIdArray;
		    var vAddressId;
		    var ctrlSubChildNodes;
		    var bFind = false;
		    
            for(var i = 0; i < iLen; i ++) {
		        ctrlTreeNode = ctrlChildNodes[i];
		        vNodeId = ctrlTreeNode.getAttribute("ID");    
		        vNodeIdArray = vNodeId.split("_")
		        vAddressId = vNodeIdArray[0];
		        if(vAddressId == findAddrId) {		           
		            bFind = true;
		            break;       
		        }
		        else {
		            ctrlSubChildNodes = ctrlTreeNode.getChildren();
		            ctrlTreeNode = recursionFind(ctrlSubChildNodes,findAddrId);
		            if(null != ctrlTreeNode) {
		                bFind = true;
		                break;
		            } 
		        }
		    }
            
            if(bFind)
                return ctrlTreeNode;
            else
                return null;
        }
        //编辑页面保存成功的时候  调用的方法
        function doTrigger() {		    
		     doOperOriParentNode();  
		}
		//找原父节点
		function doOperOriParentNode() { 
		    var isAddNew = $get("_hidAddNewSign").value;   //是否为编辑 1:编辑 
		    var curNodeExpr = $get("_hidNewColumnId").value;   //获取的是当前编辑的节点对象 eg:{"columnId":"26","columnName":"测试类型","hasChild":"1"}
		            eval("var curNodeObj=" + curNodeExpr);		           
		            var groupname = curNodeObj.groupname;
		            var ctrClickObj = findTreeNode(curNodeObj.groupId);	 
		            //alert(colName);   
		    if(isAddNew=="1"){//编辑  
		            ctrClickObj.setAttribute("Text",groupname);
		            return;  
		    }
		    else
		    {
		        var vDtNodeIndex = "0";
		        if(ctrClickObj!=null)		        
		        {
		            vDtNodeIndex = ctrClickObj.getNodeIndex();	
		        } 
		        createSubTNodes(vDtNodeIndex,curNodeObj);
		         var ctrlTree = document.getElementById("trvDepAddress");	
		         var ctrlRoot = ctrlTree.getTreeNode("0");
		         var ctrlDtNode = ctrlRoot;	
		         ctrlDtNode.setAttribute("EXPANDED",true);
		    }
		    DoSelIndex(curNodeObj);
		    return;		    
		}
		function DoSelIndex(curNodeObj)
		{
		  var nodes = new Array();
          var node=trvDepAddress.getTreeNode("0");   
          nodes = node.getChildren(); 
          for (var i = 0; i < nodes.length; i++) {
               var cNode=nodes[i]; 
               var checkNodeId=cNode.getAttribute("ID");
               if(curNodeObj.groupId==checkNodeId)
               {
                   var nodeIndex = cNode.getNodeIndex();
                   trvDepAddress.selectedNodeIndex = nodeIndex; 
                   break;
               }
            } 
		}
		 //追加子节点
        function createSubTNodes(nodeIndex,oResult) { 
			     var node = $get("trvDepAddress").getTreeNode(nodeIndex);  
			     var vPageParam = "GroupId="+oResult.groupId;
                 var encodeParam = base64encode(vPageParam);
                 vNavigateUrl = "group_personal_list.aspx?" + encodeParam;
                 oSubNode = $get("trvDepAddress").createTreeNode();
		         oSubNode.setAttribute("ID",oResult.groupId);
		         oSubNode.setAttribute("Text",oResult.groupname);
		         oSubNode.setAttribute("Type","root");
		         oSubNode.setAttribute("Target","iFrmEdit");
		         oSubNode.setAttribute("ImageUrl","../images/toolbar/filelogo.gif");
		         oSubNode.setAttribute("NavigateUrl",vNavigateUrl); 
		         node.add(oSubNode); 
        }   
		function initialTreeNode(ctrlFindNode) {
		    var ctrlTree = document.getElementById("trvDepAddress");	
		    var vNodeId;
		    var vNodeIdArray;
		    var vAddrId;	
		    var vNodeIndex;
		    var vNodeState;
		    if(null != ctrlFindNode) {
		        vNodeId = ctrlFindNode.getAttribute("ID");    
		        vNodeIdArray = vNodeId.split("_");
		        vAddrId = vNodeIdArray[0]; 
		        ctrlFindNode.setAttribute("ID",vAddrId);
		        vNodeIndex = ctrlFindNode.getNodeIndex();
		        ctrlTree.selectedNodeIndex = vNodeIndex;
		        /* 如果当前节点没有下级节点，则不会触发expand事件,
		         * 此时需要在当前节点下增加一个空节点 */
		        var vChildNodes = ctrlFindNode.getChildren();
		        if(vChildNodes.length == 0) {
		           var oEmptyNode = $get("trvDepAddress").createTreeNode();  
		           ctrlFindNode.add(oEmptyNode);
		        }
		        ctrlFindNode.setAttribute("EXPANDED",true);
		    }
		}
		
		function initializeAddNew(vUserId)
		{
	        var nodeIndex = trvDepAddress.selectedNodeIndex;
            var  node = trvDepAddress.getTreeNode(nodeIndex);  
            var vNodeId = node.getAttribute("ID");
            var vNodeIdArray = vNodeId.split("_")
            var vAddressId = vNodeIdArray[0]; 
            if(vAddressId!="0")
            {
                var MsDetail = {};
                    MsDetail.GroupId = vAddressId;
                    MsDetail.UserId = vUserId;
                    var jsonExpr = JSON.stringify(MsDetail,function(key,value){return value;}); 
                          MsDetail = null; 
                    PageMethods.DoSaveDetail(jsonExpr,ClientCBack);
            }
		}
		function ClientCBack(vResult)
        {
                eval("resultObj ="+vResult)
                if(resultObj.result!="-1")
                {
                     alert(resultObj.message);
                     var vPageParam = "GroupId=" + resultObj.resultSign;
                     var encodeParam = base64encode(vPageParam);
                     parent.frames[1].document.location.href = "group_personal_list.aspx?" + encodeParam;
                }
                else
                {
                    alert(resultObj.message);
                }
        }
    //-->
    </script>
    <script type="text/javascript">
    <!--
        $(document).ready(function(){   
            var GroupId = document.getElementById("_hidUpAddrId").value;  
            var organPageParam="GroupId="+GroupId;     
            var organEncodeParam=base64encode(organPageParam);
            var URL = "group_personal_list.aspx?"+organEncodeParam;
            parent.frames[1].document.location.href= URL;
        });
    //-->
    </script>
    </ccit:ActionForm>
</body>
</html>
